package com.example.logic.chapter10;

import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

public class EnumMapDemo {
    enum Size {
        SMALL, MEDIUM, LARGE
    }

    static class Clothes {
        String id;
        Size size;

        public Clothes(String id, Size size) {
            this.id = id;
            this.size = size;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public Size getSize() {
            return size;
        }

        public void setSize(Size size) {
            this.size = size;
        }
    }

    public static Map<Size, Integer> countBySize(List<Clothes> clothes) {
        Map<Size, Integer> map = new EnumMap<>(Size.class);
        for (Clothes clothe : clothes) {
            Integer count = map.get(clothe.getSize());
            if (count != null) {
                map.put(clothe.getSize(), count + 1);
            } else {
                map.put(clothe.getSize(), 1);

            }
        }
        return map;
    }

    public static void main(String[] args) {
        List<Clothes> clothes = Arrays.asList(new Clothes[]{
                new Clothes("C001", Size.SMALL), new Clothes("C002", Size.LARGE),
                new Clothes("C003", Size.LARGE), new Clothes("C004", Size.MEDIUM),
                new Clothes("C005", Size.SMALL), new Clothes("C006", Size.SMALL),
        });
        System.out.println(countBySize(clothes));
    }
}
